package com.pybox.api;

import com.pybox.service.TWeekTimeService;
import com.pybox.dto.TWeekTimeDto;

import com.pybox.dto.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
* 描述：TWeekTime Api
* @author wuyingkai
* @date 2018-09-15
*/

@Slf4j
@RequestMapping("/TWeekTime")
@Api(tags = "TWeekTime管理接口", description = "TWeekTime管理接口")
@RestController
public class TWeekTimeApi {

    @Autowired
    private TWeekTimeService service;

    @ApiOperation(value = "创建TWeekTime", notes = "创建TWeekTime")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public Result<Boolean> save(@RequestBody TWeekTimeDto dto) {
        service.create(dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "删除TWeekTime", notes = "删除TWeekTime")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    @ApiImplicitParam(name = "id", value = "TWeekTime id", dataType = "String", paramType = "path")
    public Result<Boolean> delete(@PathVariable("id") Integer id) {
        service.delete(id);
        return Result.ok(true);
    }

    @ApiOperation(value = "更新TWeekTime", notes = "更新TWeekTime")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.PUT)
    @ApiImplicitParam(name = "id", value = "TWeekTime id", dataType = "String", paramType = "path")
    public Result<Boolean> update(@PathVariable("id") Integer id, @RequestBody TWeekTimeDto dto) {
        service.update(id, dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "查询TWeekTime", notes = "查询TWeekTime")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "id", value = "TWeekTime id", dataType = "String", paramType = "path")
    public Result<TWeekTimeDto> detail(@PathVariable("id") Integer id) {

        return Result.ok(service.detail(id));
    }

    @ApiOperation(value = "分页查询TWeekTime", notes = "分页查询TWeekTime")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ApiImplicitParams({
           @ApiImplicitParam(name = "id", value = "id", dataType = "Integer", paramType = "query"),
           @ApiImplicitParam(name = "groupId", value = "groupId", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "dayofweek", value = "dayofweek", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour0", value = "hour0", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour1", value = "hour1", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour2", value = "hour2", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour3", value = "hour3", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour4", value = "hour4", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour5", value = "hour5", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour6", value = "hour6", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour7", value = "hour7", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour8", value = "hour8", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour9", value = "hour9", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour10", value = "hour10", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour11", value = "hour11", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour12", value = "hour12", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour13", value = "hour13", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour14", value = "hour14", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour15", value = "hour15", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour16", value = "hour16", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour17", value = "hour17", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour18", value = "hour18", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour19", value = "hour19", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour20", value = "hour20", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour21", value = "hour21", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour22", value = "hour22", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "hour23", value = "hour23", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "ctime", value = "ctime", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "utime", value = "utime", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "pageNo", value = "pageNo", dataType = "int", paramType = "query"),
        @ApiImplicitParam(name = "pageSize", value = "pageSize", dataType = "int", paramType = "query")
    })
    public Result<Page<TWeekTimeDto>> page(
                        @RequestParam(required = false) Integer id,
                        @RequestParam(required = false) String groupId,
                        @RequestParam(required = false) String dayofweek,
                        @RequestParam(required = false) String hour0,
                        @RequestParam(required = false) String hour1,
                        @RequestParam(required = false) String hour2,
                        @RequestParam(required = false) String hour3,
                        @RequestParam(required = false) String hour4,
                        @RequestParam(required = false) String hour5,
                        @RequestParam(required = false) String hour6,
                        @RequestParam(required = false) String hour7,
                        @RequestParam(required = false) String hour8,
                        @RequestParam(required = false) String hour9,
                        @RequestParam(required = false) String hour10,
                        @RequestParam(required = false) String hour11,
                        @RequestParam(required = false) String hour12,
                        @RequestParam(required = false) String hour13,
                        @RequestParam(required = false) String hour14,
                        @RequestParam(required = false) String hour15,
                        @RequestParam(required = false) String hour16,
                        @RequestParam(required = false) String hour17,
                        @RequestParam(required = false) String hour18,
                        @RequestParam(required = false) String hour19,
                        @RequestParam(required = false) String hour20,
                        @RequestParam(required = false) String hour21,
                        @RequestParam(required = false) String hour22,
                        @RequestParam(required = false) String hour23,
                        @RequestParam(required = false) String ctime,
                        @RequestParam(required = false) String utime,
                    @RequestParam(required = true) Integer pageNo,
                    @RequestParam(required = true) Integer pageSize) {

        Map<String, String> params = new HashMap<>();

                params.put("groupId",groupId);
                params.put("dayofweek",dayofweek);
                params.put("hour0",hour0);
                params.put("hour1",hour1);
                params.put("hour2",hour2);
                params.put("hour3",hour3);
                params.put("hour4",hour4);
                params.put("hour5",hour5);
                params.put("hour6",hour6);
                params.put("hour7",hour7);
                params.put("hour8",hour8);
                params.put("hour9",hour9);
                params.put("hour10",hour10);
                params.put("hour11",hour11);
                params.put("hour12",hour12);
                params.put("hour13",hour13);
                params.put("hour14",hour14);
                params.put("hour15",hour15);
                params.put("hour16",hour16);
                params.put("hour17",hour17);
                params.put("hour18",hour18);
                params.put("hour19",hour19);
                params.put("hour20",hour20);
                params.put("hour21",hour21);
                params.put("hour22",hour22);
                params.put("hour23",hour23);
                params.put("ctime",ctime);
                params.put("utime",utime);
        return Result.ok(service.page(pageNo, pageSize, params));
    }
}